package com.yunda.nebula.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * \* User: wei.zhang
 * \* Date: 2019/11/8 9:13
 * \* Description:
 * \
 */
@Component
@Slf4j
public class TokenAuthGatewayFilterFactory extends AbstractGatewayFilterFactory<Object> implements ApplicationContextAware {
    @Autowired
    private TokenAuthGatewayFilter tokenAuthGatewayFilter;

    @Override
    public GatewayFilter apply(Object config) {
        log.info("开始初始化token过滤器");
//        TokenAuthGatewayFilter tokenAuthGatewayFilter =  new  TokenAuthGatewayFilter();
        return tokenAuthGatewayFilter;
    }

//    @Override
//    public String name() {
//        return "TokenAuthGateway";
//    }

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
